<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_symbolExtendProperty"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            width: 220px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }

        .input-group {
            margin-bottom: 15px;
        }

        .winContent {
            padding: 5px;
            overflow-y: auto;
            height: 300px;

        }

        .popupWindow {
            position: absolute;
            right: 10px;
            top: 280px;
            width: 220px;
            background: #FFF;
            z-index: 9999;
            display: block;
        }

        .winTitle {
            background: #1E90FF;
        }

    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_symbolExtendProperty"></h5></div>
    <div class='panel-body content'>
        <div class='panel'>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_propertyName"></span>
                <input class='form-control' id='propertyName' value=''/>
            </div>
            <div class='input-group'>
                <span class='input-group-addon' data-i18n="resources.text_propertyValue"></span>
                <input class='form-control' id='propertyValue' value=''/>
            </div>
        </div>
        <input id="btn" type="button" class="btn  btn-default" data-i18n="[value]resources.btn_addProperty" onclick="addExtendProperty()"/>
    </div>
</div>
<div id="popupWin" class="panel panel-primary popupWindow">
    <div class="winTitle">
        <span class="title_left" data-i18n="resources.title_symbolExtendProperty"></span>
    </div>
    <div id="extendProperty" class="winContent"></div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
<script>
    var plottingLayer, plottingEdit, layer, map;
    var host = window.isLocal ? window.server : "http://iclsvr.supermap.io";
    var mapurl = host + "/iserver/services/map-world/rest/maps/World";
    var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});

        plottingLayer = new SuperMap.Layer.PlottingLayer("标绘图层", serverUrl);
        plottingLayer.style = {
            fillColor: "#66cccc",
            fillOpacity: 0.4,
            strokeColor: "#66cccc",
            strokeOpacity: 1,
            strokeWidth: 3,
            pointRadius: 6
        };

        //态势标绘编辑
        plottingEdit = new SuperMap.Control.PlottingEdit();

        plottingLayer.events.on({"featureselected": showExtendProperty});
        plottingLayer.events.on({"featuremodified": showExtendProperty});
        plottingLayer.events.on({"afterfeaturemodified": showExtendProperty});
        //添加态势标绘控件
        map.addControls([plottingEdit]);
    }

    function addLayer() {
        map.addLayers([layer, plottingLayer]);
        map.setCenter(new SuperMap.LonLat(0, 0), 0);

        //标绘标号
        plotSymbol();

        plottingEdit.activate();
    }

    function plotSymbol() {

        //标绘多边形
        var polygonPoints = [];
        polygonPoints.push(new SuperMap.Geometry.Point(-20, 0));
        polygonPoints.push(new SuperMap.Geometry.Point(-10, 20));
        polygonPoints.push(new SuperMap.Geometry.Point(-30, 40));
        polygonPoints.push(new SuperMap.Geometry.Point(-60, 10));
        plottingLayer.createSymbolWC(0, SuperMap.Plot.SymbolType.ARBITRARYPOLYGONSYMBOL, polygonPoints);

        //标绘折线
        var linePoints = [];
        linePoints.push(new SuperMap.Geometry.Point(0, 0));
        linePoints.push(new SuperMap.Geometry.Point(0, 20));
        linePoints.push(new SuperMap.Geometry.Point(20, 10));
        linePoints.push(new SuperMap.Geometry.Point(10, 30));
        plottingLayer.createSymbolWC(0, SuperMap.Plot.SymbolType.POLYLINESYMBOL, linePoints);
    }

    function addExtendProperty() {
        widgets.alert.clearAlert();
        var key = document.getElementById("propertyName").value;
        var value = document.getElementById("propertyValue").value;
        if ("" === key || "" === value) {
            return;
        }

        var features = plottingLayer.selectedFeatures;
        if (0 === features.length) {
            widgets.alert.showAlert(resources.msg_selectFeature, true);
            return;
        }

        var geometry = features[0].geometry;
        var extendProperty = geometry.getExtendProperty();
        extendProperty.addProperty(key, value);

        showExtendProperty();
    }

    function showExtendProperty() {
        document.all.extendProperty.innerHTML = "";

        //获取选中的对象
        var features = plottingLayer.selectedFeatures;
        if (0 === features.length) {
            return;
        }

        var geometry = features[0].geometry;
        var extendProperty = geometry.getExtendProperty();

        var nPropertyCount = extendProperty.getPropertyCount();
        if (0 === nPropertyCount) {
            return;
        }

        var container = document.getElementById("extendProperty");
        var table = document.createElement("table");
        var body = document.createElement("tbody");
        table.setAttribute("border", "1");
        table.setAttribute("borderColor", "black");
        table.setAttribute("width", "100%");

        var tr = document.createElement("tr");

        //添加属性名
        var td_Name = document.createElement("th");
        var text_Name = document.createTextNode(resources.text_propertyName);
        td_Name.appendChild(text_Name);
        tr.appendChild(td_Name);

        //添加属性值
        var td_Value = document.createElement("th");
        var text_Value = document.createTextNode(resources.text_propertyValue);
        td_Value.appendChild(text_Value);
        tr.appendChild(td_Value);
        body.appendChild(tr);

        for (var i = 0; i < nPropertyCount; i++) {
            var property = extendProperty.getPropertyByIndex(i);
            if (null === property) {
                continue;
            }

            var _tr = document.createElement("tr");

            //添加属性名
            var td_PropertyName = document.createElement("td");
            var text_propertyName = document.createTextNode(property.getKey());
            td_PropertyName.appendChild(text_propertyName);
            _tr.appendChild(td_PropertyName);

            //添加属性值
            var td_PropertyValue = document.createElement("td");
            var text_propertyValue = document.createTextNode(property.getValue());
            td_PropertyValue.appendChild(text_propertyValue);
            _tr.appendChild(td_PropertyValue);


            body.appendChild(_tr);
        }

        table.appendChild(body);
        container.appendChild(table);
    }
</script>

</body>
</html>